﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LanceZhang.Research.BLL;
using LanceZhang.Research.Model;

public partial class UserControl_UserManage : System.Web.UI.UserControl
{
    bool canedit = false;
    string where = "1=1";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["where"] == null)
        {

        }
        else
        {
            //若是查询
            where = Request.QueryString["where"];
        }

        TBL_User bc = new TBL_User();
        grdMain.DataSource = bc.GetList(where);
        grdMain.DataBind();

        #region 权限判断

        List<string> role = (List<string>)(Session["UR"]);
        string r = "R01";
        if (role.Contains(r))
        {
            canedit = true;
        }

        #endregion

    }
    protected void grdMain_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "View":
                //
                Response.Redirect("MyInfo.aspx?id=" + grdMain.DataKeys[Convert.ToInt16(e.CommandArgument)].Value.ToString());
                break;
            case "IUpdate":
                //
                if (canedit)
                {
                    Response.Redirect("UserUpdate.aspx?id=" + grdMain.DataKeys[Convert.ToInt16(e.CommandArgument)].Value.ToString());
                }
                else
                {
                    Page.RegisterStartupScript("warnings", "<script>alert('您无此权限');</script>");
                }
                break;
            case "Del":
                //
                if (canedit)
                {
                    Page.RegisterStartupScript("warnings", "<script>confirm('确定删除吗?');</script>");
                    //
                    TBL_User c = new TBL_User();
                    TBL_UserModel u=c.GetModelByCache(grdMain.DataKeys[Convert.ToInt16(e.CommandArgument)].Value.ToString());
                    u.Status=false;
                    c.Update(u);
                    Page_Load(sender, e);
                }
                else
                {
                    Page.RegisterStartupScript("warnings", "<script>alert('您无此权限');</script>");
                }
                break;
        }
    }
    protected void grdMain_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        TBL_User bc = new TBL_User();
        grdMain.PageIndex = e.NewPageIndex;
        grdMain.DataSource = bc.GetList(where);
        grdMain.DataBind();
    }
    protected void BtnAdd_Click(object sender, EventArgs e)
    {
        Server.Transfer("UserAdd.aspx");
    }
}
